UNIT TCPPB;

INTERFACE

{ Command codes }

CONST
	TCPCreate = 30;
	TCPPassiveOpen = 31;
	TCPActiveOpen = 32;
	TCPActiveOpenWithData = 33;
	TCPSend = 34;
	TCPNoCopyRcv = 35;
	TCPRcvBfrReturn = 36;
	TCPRcv = 37;
	TCPClose = 38;
	TCPAbort = 39;
	TCPStatus = 40;
	TCPExtendedStat = 41;
	TCPRelease = 42;
	TCPGlobalInfo = 43;

TYPE
	TCPEventCode = (TCPNone, TCPClosing, TCPULPTimeout, TCPTerminate,
					TCPDataArrival, TCPUrgent, TCPICMPReceived);

	TCPTerminationReason = (Fill0, Fill1, TCPRemoteAbort, TCPNetworkFailure,
							TCPSecPrecMismatch, TCPULPTimeoutTerminate, TCPULPAbort,
							TCPULPClose, TCPServiceError); 

	TCPNotifyProcPtr = ProcPtr;
	{ PROCEDURE TCPNotifyProc(tcpStream		: StreamPtr;
							  eventCode		: TCPEventCode;
							  userDataPtr	: Ptr;
							  terminReason	: TCPTerminationReason;
							  icmpMsg		: ICMPReportPtr); }

	TCPIOCompletionProcPtr	=	ProcPtr;
	{ PROCEDURE TCPIOCompletionProc(iopb	: TCPiopbPtr); }

	tcp_port	=	Integer;

CONST
	{ ValidityFlags }
	timeoutValue	=	$80;
	timeoutAction	=	$40;
	typeOfService	=	$20;
	precedence		=	$10;

	{ TOSFlags }
	lowDelay		=	$01;
	throughPut		=	$02;
	reliability		=	$04;

TYPE
	TCPCreatePB	=	RECORD
		rcvBuff		:	Ptr;
		rcvBuffLen	:	LongInt;
		notifyProc	:	TCPNotifyProcPtr;
		userDataPtr	:	Ptr;
	END;

	TCPOpenPB	=	RECORD
		ulpTimeoutValue		:	SignedByte;
		ulpTimeoutAction	:	SignedByte;
		validityFlags		:	SignedByte;
		commandTimeoutValue	:	SignedByte;
		remoteHost			:	ip_addr;
		remotePort			:	tcp_port;
		localHost			:	ip_addr;
		localPort			:	tcp_port;
		tosFlags			:	SignedByte;
		precedence			:	SignedByte;
		dontFrag			:	Boolean;
		timeToLive			:	SignedByte;
		security			:	SignedByte;
		optionCnt			:	SignedByte;
		options				:	PACKED ARRAY [0..39] OF SignedByte;
		userDataPtr			:	Ptr;
	END;
	
	TCPOpenWithDataPB	=	RECORD
		ulpTimeoutValue		:	SignedByte;
		ulpTimeoutAction	:	SignedByte;
		validityFlags		:	SignedByte;
		commandTimeoutValue	:	SignedByte;
		remoteHost			:	ip_addr;
		remotePort			:	tcp_port;
		localHost			:	ip_addr;
		localPort			:	tcp_port;
		tosFlags			:	SignedByte;
		precedence			:	SignedByte;
		dontFrag			:	Boolean;
		timeToLive			:	SignedByte;
		security			:	SignedByte;
		optionCnt			:	SignedByte;
		options				:	PACKED ARRAY [0..39] OF SignedByte;
		pushFlag			:	Boolean;
		urgentFlag			:	Boolean;
		wdsPtr				:	Ptr;
		sendFree			:	LongInt;
		userDataPtr			:	Ptr;
	END;

	TCPSendPB		=		RECORD
		ulpTimeoutValue		:	SignedByte;
		ulpTimeoutAction	:	SignedByte;
		validityFlags		:	SignedByte;
		pushFlag			:	Boolean;
		urgentFlag			:	Boolean;
		wdsPtr				:	Ptr;
		sendFree			:	LongInt;
		sendLength			:	Integer;
		userDataPtr			:	Ptr;
	END;
	

	TCPReceivePB	=	RECORD	{ for receive and return rcv buff calls }
		commandTimeoutValue	:	SignedByte;
		filler				:	SignedByte;
		urgentFlag			:	Boolean;
		markFlag			:	Boolean;
		rcvBuff				:	Ptr;
		rcvBuffLen			:	Integer;
		rdsPtr				:	Ptr;
		rdsLength			:	Integer;
		secondTimeStamp		:	Integer;
		userDataPtr			:	Ptr;
	END;
	
	TCPClosePB		=	RECORD
		ulpTimeoutValue		:	SignedByte;
		ulpTimeoutAction	:	SignedByte;
		validityFlags		:	SignedByte;
		userDataPtr			:	Ptr;
	END;
	
	HistoBucket		=	RECORD
		value	:	Integer;
		counter	:	LongInt;
	END;
	
CONST
	NumOfHistoBuckets	=	7;

TYPE
	TCPConnectionStats	=	RECORD
		dataPktsRcvd	:	LongInt;
		dataPktsSent	:	LongInt;
		dataPktsResent	:	LongInt;
		bytesRcvd		:	LongInt;
		bytesRcvdDup	:	LongInt;
		bytesRcvdPastWindow	:	LongInt;
		bytesSent		:	LongInt;
		bytesResent		:	LongInt;
		numHistoBuckets	:	Integer;
		sentSizeHisto	:	ARRAY [0..NumOfHistoBuckets-1] OF HistoBucket;
		lastRTT			:	Integer;
		tmrSRTT			:	Integer;
		rttVariance		:	Integer;
		tmrRTO			:	Integer;
		sendTries		:	SignedByte;
		sourceQuenchRcvd:	SignedByte;
	END;

	TCPConnectionStatsPtr	=	TCPConnectionStats;
	
	TCPStatusPB		=	RECORD
		ulpTimeoutValue	:	SignedByte;
		ulpTimeoutAction:	SignedByte;
		unused			:	LongInt;
		remoteHost		:	ip_addr;
		remotePort		:	tcp_port;
		localHost		:	ip_addr;
		localPort		:	tcp_port;
		tosFlags		:	SignedByte;
		precedence		:	SignedByte;
		connectionState	:	SignedByte;
		sendWindow		:	Integer;
		rcvWindow		:	Integer;
		amtUnpackedData	:	Integer;
		amtUnreadData	:	Integer;
		securityLevelPtr:	Ptr;
			{ HEMS-HEMP stats }
		sendUnacked		:	LongInt;
		sendNext		:	LongInt;
		congestionWindow:	LongInt;
		rcvNext			:	LongInt;
		srtt			:	LongInt;
		lastRTT			:	LongInt;
		sendMaxSegSize	:	LongInt;
		connStatPtr		:	TCPConnectionStatsPtr;
		userDataPtr		:	Ptr;
	END;
	
	TCPAbortPB		=	RECORD
		userDataPtr		:	Ptr;
	END;
	
	TCPParam		=	RECORD
		tcpRtoA			:	LongInt;
		tcpRtoMin		:	LongInt;
		tcpRtoMax		:	LongInt;
		tcpMaxSegSize	:	LongInt;
		tcpMaxConn		:	LongInt;
		tcpMaxWindow	:	LongInt;
	END;
	TCPParamPtr		=	^TCPParam;

	TCPStats		=	RECORD
		tcpConnAttempts		:	LongInt;
		tcpConnOpened		:	LongInt;
		tcpConnAccepted		:	LongInt;
		tcpConnClosed		:	LongInt;
		tcpConnAborted		:	LongInt;
		tcpOctetsIn			:	LongInt;
		tcpOctetsOut		:	LongInt;
		tcpOctetsInDup		:	LongInt;
		tcpOctetsRetrans	:	LongInt;
		tcpInputPkts		:	LongInt;
		tcpOutputPkts		:	LongInt;
		tcpDupPkts			:	LongInt;
		tcpRetransPkts		:	LongInt;
	END;
	TCPStatsPtr		=	^TCPStats;
	
	TCPGlobalInfoPB	=	RECORD
		tcpParamP	:	TCPParamPtr;
		tcpStatsP	:	TCPStatsPtr;
		tcpCDBTable	:	Ptr;
		userDataPtr	:	Ptr;
	END;
	
	TCPiopb		=	RECORD
		fill12		:	ARRAY [0..11] OF SignedByte;
		ioCompletion:	TCPIOCompletionProcPtr;
		ioResult	:	Integer;
		ioNamePtr	:	Ptr;
		ioVRefNum	:	Integer;
		ioCRefNum	:	Integer;
		csCode		:	Integer;
		tcpStream	:	StreamPtr;
		CASE Integer OF
			1:	(create			:	TCPCreatePB);
			2:	(open			:	TCPOpenPB);
			3:	(openWithData	:	TCPOpenWithDataPB);
			4:	(send			:	TCPSendPB);
			5:	(receive		:	TCPReceivePB);
			6:	(close			:	TCPClosePB);
			7:	(abort			:	TCPAbortPB);
			8:	(status			:	TCPStatusPB);
			9:	(globalInfo		:	TCPGlobalInfoPB);
	END;
	
	TCPiopbPtr		=	^TCPiopb;
	
IMPLEMENTATION 

END.
	
